Relayout Hard Drive 2

Backup and Mount Root/SWAP LVM Partition

Backup the / partition (which is in the same partion as SWAP). I do this before replacing the OS so I can refer back to anything if required.

dd if=/dev/nvme0n1p3 of=laptop-root-luks.dd bs=2048

Decrypt the LUKS file.

cryptsetup open laptop-root-luks.dd laptop2

Use vgdisplay to see the details

vgdisplay

Use lvscan to see the details

lvscan

To resolve the clash of LVM IDs use vgimportclone

vgimportclone -n laptopclone /dev/mapper/laptop2

Activate the LVM

vgchange --activate y laptopclone

Mount the filesystem - read only.

mount -o ro /dev/laptopclone/root /media/external/

Then lots of messing around...


On OTHER Computer
=================

cryptsetup luksOpen /dev/loop11 laptop3

losetup -P /dev/loop11 sda3

lsblk --fs

loop11         crypto_       6b1a9ade-99a7-4778-baf0-106bd2f21254   

cryptsetup luksOpen /dev/loop11 laptop3

loop11         crypto_       6b1a9ade-99a7-4778-baf0-106bd2f21254   
└─laptop3      LVM2_me       jYehGk-S1MJ-NuKR-r0P5-EETN-KCKw-xKzR1q 
  ├─vgubuntu--budgie-root
  │            ext4          9f8acff1-7066-4241-a009-d8c21b8f5171   
  └─vgubuntu--budgie-swap_1
               swap          2ecd31c7-b3af-40d9-95f5-150f53793c01 
               

sudo vgscan                 #Scans for LVM Volume Group(s)
sudo vgchange -ay           #Activates LVM Volume Group(s)
sudo lvscan                 #Scans for available Logical Volumes

mount /dev/vgubuntu-budgie/root /media/laptop/

cp -a /media/laptop .


On LAPTOP:
==========

lsblk --fs

sda                                                                     
├─sda1
│    vfat         61BA-CECE                                             
├─sda2
│    ext4         f731f8da-2a13-470b-9e3c-8b1a63de5409                  
└─sda3
     crypto       6b1a9ade-99a7-4778-baf0-106bd2f21254                  
  └─luks-6b1a9ade-99a7-4778-baf0-106bd2f21254
     LVM2_m       jYehGk-S1MJ-NuKR-r0P5-EETN-KCKw-xKzR1q                
    ├─vgubuntu--budgie-root
    │  ext4         9f8acff1-7066-4241-a009-d8c21b8f5171                  
    └─vgubuntu--budgie-swap_1
       swap         2ecd31c7-b3af-40d9-95f5-150f53793c01  

root@ubuntu-budgie:~# pvdisplay
  --- Physical volume ---
  PV Name               /dev/mapper/luks-6b1a9ade-99a7-4778-baf0-106bd2f21254
  VG Name               vgubuntu-budgie
  PV Size               <445.90 GiB / not usable 0   
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              114150
  Free PE               0
  Allocated PE          114150
  PV UUID               jYehGk-S1MJ-NuKR-r0P5-EETN-KCKw-xKzR1q

root@ubuntu-budgie:~# vgdisplay
  --- Volume group ---
  VG Name               vgubuntu-budgie
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <445.90 GiB
  PE Size               4.00 MiB
  Total PE              114150
  Alloc PE / Size       114150 / <445.90 GiB
  Free  PE / Size       0 / 0   
  VG UUID               EUe57a-wRUf-Ams2-Q9cW-cpcV-oJy5-HaF8X0

root@ubuntu-budgie:~# lvdisplay
  --- Logical volume ---
  LV Path                /dev/vgubuntu-budgie/root
  LV Name                root
  VG Name                vgubuntu-budgie
  LV UUID                TrJrKx-2K0l-UtnA-Of0C-CnTj-OIHC-1Pj02f
  LV Write Access        read/write
  LV Creation host, time ubuntu-budgie, 2020-05-10 14:41:42 +0000
  LV Status              available
  # open                 0
  LV Size                444.94 GiB
  Current LE             113905
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1
   
  --- Logical volume ---
  LV Path                /dev/vgubuntu-budgie/swap_1
  LV Name                swap_1
  VG Name                vgubuntu-budgie
  LV UUID                1QWtHe-uxd2-gYNt-Uoed-8V3p-2jNI-Wxxh34
  LV Write Access        read/write
  LV Creation host, time ubuntu-budgie, 2020-05-10 14:41:42 +0000
  LV Status              available
  # open                 0
  LV Size                980.00 MiB
  Current LE             245
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:2



fdisk -l

Disk /dev/mapper/luks-6b1a9ade-99a7-4778-baf0-106bd2f21254: 445.92 GiB, 478780850176 bytes, 935118848 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/vgubuntu--budgie-root: 444.96 GiB, 477752197120 bytes, 933109760 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/vgubuntu--budgie-swap_1: 980 MiB, 1027604480 bytes, 2007040 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


DO IT
=====
lvremove /dev/vgubuntu-budgie/swap_1
lvremove /dev/vgubuntu-budgie/root

pvresize --setphysicalvolumesize 40G /dev/mapper/luks-6b1a9ade-99a7-4778-baf0-106bd2f21254 

cryptsetup remove /dev/mapper/luks-6b1a9ade-99a7-4778-baf0-106bd2f21254

fdisk /dev/sda

Create smaller partition

cryptsetup -y -v luksFormat /dev/sda3

└─sda3
     crypto       32940867-7d32-4270-a6cb-87e2705622aa 
     
cryptsetup open /dev/sda3 luks-6b1a9ade-99a7-4778-baf0-106bd2f21254

pvcreate /dev/mapper/luks-6b1a9ade-99a7-4778-baf0-106bd2f21254

vgcreate vgubuntu-budgie /dev/mapper/luks-6b1a9ade-99a7-4778-baf0-106bd2f21254

lvcreate -L 980M vgubuntu-budgie -n swap_1

lvcreate -l 100%FREE vgubuntu-budgie -n root

mkswap /dev/vgubuntu-budgie/swap_1 

mkfs.ext4 /dev/vgubuntu-budgie/root 

mount /dev/vgubuntu-budgie/root  /media/steve

cp -a /media/orig /media/steve

NEW:

├─sda3
│    crypto       32940867-7d32-4270-a6cb-87e2705622aa                  
│ └─luks-6b1a9ade-99a7-4778-baf0-106bd2f21254
│    LVM2_m       JYNn1f-0mTD-2KQS-uB1h-S8yI-IpVd-zJNF5J                
│   ├─vgubuntu--budgie-swap_1
│   │  swap         2ceed984-4551-4ed9-8d44-c2f742c10924                  
│   └─vgubuntu--budgie-root
│      ext4         3156272b-58f9-45df-9290-49df86172a9e 

 cryptsetup luksUUID /dev/sda1 --uuid "6b1a9ade-99a7-4778-baf0-106bd2f21254"
 
 Must match /etc/crypttab